def day_wise_analyze():
  # 修改文件路径
  import os
  current_dir = os.path.dirname(os.path.abspath(__file__))
  data_file_path = os.path.join(current_dir, "..", "..", "data", "day_wise.csv")

  with open(data_file_path, "r", encoding="utf-8") as f:
    data = f.readlines()

  covid = {
    "date": [],
    "data": [],
    "header": [h for h in data[0].strip().split(",")[1:]]
  }
  for row in data[1:]:
    split_row = row.strip().split(",")
    covid["date"].append(split_row[0])
    covid["data"].append([float(n) for n in split_row[1:]])
  print("日期列表摘取：", covid["date"][:4])

  date_idx = covid["date"].index("2020-02-03")
  print("日期->索引转换：", date_idx)

  import numpy as np
  data = np.array(covid["data"])

  for header, number in zip(covid["header"], data[date_idx]):
    print(header, ":", number)

  row_idx = covid["date"].index("2020-01-24")  # 获取日期索引
  column_idx = covid["header"].index("Confirmed")  # 获取标题的索引
  confirmed0124 = data[row_idx, column_idx]
  print("截止 1 月 24 日的累积确诊数：", confirmed0124)

  row_idx = covid["date"].index("2020-07-23")  # 获取日期索引
  column_idx = covid["header"].index("New deaths")  # 获取标题的索引
  result = data[row_idx, column_idx]
  print("截止 7 月 23 日的新增死亡数：", result)

  new_cases_idx = covid["header"].index("New cases")
  # 修改导入路径
  import sys
  sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  from learn_matplotlib.draw_line_example import draw_line
  draw_line(data[:, new_cases_idx])


if __name__ == '__main__':
  day_wise_analyze()
